package com.example.su_shi_tan_bas_lib.utils;

import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.util.Log;

import androidx.core.content.FileProvider;

import java.io.File;

public class FileProviderHelper {

    public static Uri getFormFileUri(Context context, File file){
        Uri fileUri;
        if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
            fileUri = getFormFileUriByAndroidN(context,file);
        }else {
            fileUri =getFormFileUriByNormal(file);
        }
        return fileUri;
    }

    private static Uri getFormFileUriByNormal( File file) {
        return Uri.fromFile(file);
    }

    private static Uri getFormFileUriByAndroidN(Context mContext, File file) {
        String authority = mContext.getApplicationInfo().packageName + ".android.FileProvider";
        Log.d("getFormFile", "authority: "+authority);
//        Uri fileUri= FileProvider.getUriForFile(mContext.getApplicationContext(),authority,file);
        return FileProvider.getUriForFile(mContext.getApplicationContext(),authority,file);
    }
}